import os
import requests
from urllib.parse import urlparse

url = 'http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg'
desktop_path = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
filename = urlparse(url).path.split('/')[-1]
filepath = os.path.join(desktop_path, filename)
response = requests.get(url, stream=True)

if response.status_code == 200:
    with open(filepath, 'wb') as f:
        for chunk in response.iter_content(1024):
            f.write(chunk)
    print(f"图片已保存到 {filepath}")
else:
    print(f"下载失败，状态码：{response.status_code}")